5 pixles wide by 10 pixles tall how may bytes are in each row? 16 how may bytes are in the image data?160 how may bytes are in the file header? 14 how may bytes are in the info header? 40 how may bytes are in the whole file? 214 #include #include using namespace std; const unsigned int HEADER_SIZE = 54; const unsigned int BYTES_PER_PIXEL = 3; int paddingBytesNeededPerRow(int width); int bytesPerRow(int width); void writeFileHeader(ofstream& fout, int height, int width) { char bfType[3] = "BM"; unsigned int bfSize = bytesPerRow(width) * height + HEADER_SIZE; unsigned short bfReserved1 = 0; unsigned short bfReserved2 = 0; unsigned int bfOffBits = HEADER_SIZE; fout.write(bfType, 2); // this should read BM fout.write((char*)&bfSize,4); fout.write((char*)&bfReserved1,2); fout.write((char*)&bfReserved2,2); fout.write((char*)&bfOffBits,4); } void writeInfoHeader(ofstream& fout, int height, int width) { unsigned int biSize = 40; unsigned int biWidth = width; unsigned int biHeight = height; unsigned short biPlanes = 1; unsigned short biBitCount = 24; unsigned int biCompression = 0; unsigned int biSizeImage = bytesPerRow(width) * height; unsigned int biXPelsPerMeter = 0; unsigned int biYPelsPerMeter = 0; unsigned int biClrUsed = 0; unsigned int biClrImportant = 0; fout.write((char*)&biSize,4); fout.write((char*)&biWidth,4); fout.write((char*)&biHeight,4); fout.write((char*)&biPlanes,2); fout.write((char*)&biBitCount,2); fout.write((char*)&biCompression,4); fout.write((char*)&biSizeImage,4); fout.write((char*)&biXPelsPerMeter,4); fout.write((char*)&biYPelsPerMeter,4); fout.write((char*)&biClrUsed,4); fout.write((char*)&biClrImportant,4); } int bytesPerRow(int width) { int result = width * 3; while(result % 4 != 0) { result ++; } return result; } int paddingBytesNeededPerRow(int width) { return ( bytesPerRow(width) - (width * 3)); } void main() { ofstream fout("junk.bmp",ios::binary); int height; int width; cout << "Height? "; cin >> height; cout << "Width? "; cin >> width; writeFileHeader(fout, height, width); writeInfoHeader(fout, height, width); unsigned char red = 0; unsigned char blue = 0; unsigned char green = 0; unsigned int padding = 0; for(int row = 0; row < height; row++) { for(int column = 0;column < width; column++) { fout.write((char*)&blue, 1); fout.write((char*)&green, 1); fout.write((char*)&red, 1); } //may need to write extra bytes fout.write((char*)&padding,paddingBytesNeededPerRow(width)); } fout.close(); }